package com.tianyadu.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @FileName: MqReceiver
 * @Description: 消息通知
 * @author: xueyj
 * @create: 2018-11-25 21:27
 */
@Slf4j
@Component
public class MqReceiver {

    /**
     * @Description: 消息通知测试（需手动创建消息队列信息）
     *   无绑定，无分组
     * @param:
     * @return:
     * @author:
     * @date:   2018/11/25 21:30
     */
  /*  @RabbitListener(queues = "myQueue1")
    public void getMyQueue1Nodes(String message) {
        log.info("MyQueue1Nodes : {}", message);
    }*/

    /**
      * @Description: 消息通知测试（自动创建消息对列）
      * 无绑定，无分组
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 5:33
      */
    @RabbitListener(queuesToDeclare = @Queue("myQueue2"))
    public void getMyQueue2Nodes(String message) {
        log.info("MyQueue2Nodes: {}", message);
    }

    /**
      * @Description: 自动创建, Exchange和Queue绑定
      *  无绑定，无分组
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 5:35
      */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))
    public void process(String message) {
        log.info("MqReceiver: {}", message);
    }

    /**
      * @Description: 数码供应商服务 接收消息
      * 分组为computer，消息服务名称为computerOrder
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 5:52
      */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "computer",
            value = @Queue("computerOrder")
    ))
    public void processComputer(String message) {
        log.info("computer MqReceiver: {}", message);
    }

    /**
      * @Description: 水果供应商服务 接收消息
      * 分组为fruit，消息服务名称为fruitOrder
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 5:52
      */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "fruit",
            value = @Queue("fruitOrder")
    ))
    public void processFruit(String message) {
        log.info("fruit MqReceiver: {}", message);
    }
}